package MapperReduce;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author caoxiaofeng
 * @date 2021-07-13 23:03
 */

// key value map 阶段输出的key和value
public class WordCountReducer  extends Reducer<Text, IntWritable,Text,IntWritable> {

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
//        super.reduce(key, values, context);

       int sum = 0;

    // 1. 累加求和
        for (IntWritable value : values){
            sum += value.get();
        }

        //2. 写出
        IntWritable v = new IntWritable();
        v.set(sum);
        context.write(key,v);


    }
}
